import { queryUserOrder, editOrder } from '../../services/order'
import { checkIfLogin } from '../../utils/check'
import Toast from '@vant/weapp/toast/toast'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    userReportList:[],
    showDialogConfirm:false,
    dialogMsg:"",
    currentItem:{}
  },

  onLoad(){
    this.getUserOrderList()
  },

  onShow(){
    checkIfLogin()
    this.getUserOrderList()
  },

  async getUserOrderList(){
    let statusList = [2, 3]
    let orderRes = await queryUserOrder({
      statusList
    })
    if(orderRes.code === 200){
      this.setData({
        userReportList: orderRes.rows
      })          
    }
  },

  handleViewDetail(event){
    const orderId = event.detail.id
    const type = event.detail.type || ""

    wx.navigateTo({
      url: `/pages/report-list/report-list?orderId=${orderId}&type=$${type}`,
    })
  },

  handleDelete(event){
    let currentItem = event.detail
    this.setData({
      showDialogConfirm: true,
      dialogMsg: "是否确认删除?",
      currentItem,
    })
  },

  async handleConfirm(){
    let currentItem = this.data.currentItem
    let queryData = {
      id: currentItem.id,
      status: 5
    }
    let res = await editOrder(queryData)
    if(res.code == 200){
      Toast.success('删除成功!');
      this.getUserOrderList()
    }
  }
})